//
//  RegisterSecurityCodeVC2.m
//  DYLYJ
//
//  Created by JM on 15/11/21.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "RegisterSecurityCodeVC2.h"
//#import "phoneGetSMSImageRequest.h"
#import "DYUIKit.h"
#import "DYRequestAll.h"
#import "DYServer.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "RegisterQueryController2.h"
@interface RegisterSecurityCodeVC2 ()
@property(nonatomic,strong)IBOutlet UIImageView *imageViewOfYanzhengma;
@property(nonatomic,strong) PhoneGetSMSImageResponse  *rsponseGetSMSImage;
@property(nonatomic,strong)IBOutlet UITextField *codeTextFeild;
@end

@implementation RegisterSecurityCodeVC2

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.codeTextFeild setValue:@(YES) forKeyPath:@"_placeholderLabel.adjustsFontSizeToFitWidth"];
    
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    PhoneGetSMSImageRequest *request = [PhoneGetSMSImageRequest request];
    request.DY_appSecret = DY_appSecret;
    [request requstWithCompletionHandler:^(DYResponse *rs, NSError *error) {
        if (error){
            self.rsponseGetSMSImage  = [PhoneGetSMSImageResponse response];
            self.rsponseGetSMSImage.DY_token = @"2";
            self.rsponseGetSMSImage.DY_captchaId = @"3";
            [MJAlertView showAlertViewWithTitle:@"温馨提示" message:error.localizedDescription clickedButtonBlock:^(NSInteger index) {
                [self.navigationController popViewControllerAnimated:YES];
            } cancelButtonTitle:@"确定" otherButtonTitles:nil];
            return ;
        }
        PhoneGetSMSImageResponse * rsponse = (PhoneGetSMSImageResponse *)rs;
        [self.imageViewOfYanzhengma sd_setImageWithURL:[NSURL URLWithString:rsponse.DY_captchaURL]];
        //        [self.imageViewOfYanzhengma setImage:[UIImage imageNamed:@"03顶栏 Logo"]];
        self.rsponseGetSMSImage = rsponse;
    }];
}


- (IBAction)clickSendBtn:(id)sender {
    if (self.codeTextFeild.text.length == 0){
        [MJAlertView showMessage:@"请输入右侧图片中的验证码"];
        return;
    }
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    RegisterQueryController2* vc = [storyboard instantiateViewControllerWithIdentifier:@"RegisterQueryController2"];
    vc.rsponseGetSMSImage = self.rsponseGetSMSImage;
    vc.name = self.name;
    vc.pwd = _pwd;
    vc.code = self.codeTextFeild.text;
    [self.navigationController pushViewController:vc animated:YES];

}


//#pragma mark - Table view data source
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Incomplete implementation, return the number of sections
//    return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete implementation, return the number of rows
//    return 0;
//}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
